import React from 'react';
import {connect} from 'dva'
import moment from 'moment'

import MyDatePicker from 'components/MyDatePicker'

import StatisticsAlarmPie from './StatisticsAlarmPie'
import StatisticsLine from './StatisticsLine'
import StatisticsAlarmRadio from './StatisticsAlarmRadio'

const format = 'YYYY'
const nowTimeStamp = Date.now();
const now = new Date(nowTimeStamp);
const time = moment(now).format(format)

@connect(({watermeter}) => ({...watermeter}))
class Watermeter extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      time
    }
  }

  handleChange = (data) => {
    const lastTime = this.state.time;
    const time = moment(data).format(format)
    if(lastTime === time){
      return;
    }
    this.setState({
      time
    })
  }

  render() {
    const { time } = this.state;
    return (<>
      <MyDatePicker defaultValue={time} onChange={this.handleChange} />

      <StatisticsAlarmRadio
        defaultValue={time}
      />
      <StatisticsAlarmPie
        defaultValue={time}
      />
      <StatisticsLine
        defaultValue={time}
      />
    </>)
  }
}

export default Watermeter;
